/**
 * 功能:
 * 作者:周逸健
 * 日期: 2023/10/27 10:47
 */
package com.cgnfz.crm.utils;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class DateUtils {

    public String nowDateTime() {
        Date currentDate = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
        return simpleDateFormat.format(currentDate);
    }

    public long getDaySub(Date beginDate, Date endDate) {
        long day = 0;
        try {
            day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            e.getStackTrace();
        }
        return day;

    }

    public Date getCurrentDate() {
        return new Date(); // 获取当前时间
    }

    public String getCurrentDateStr() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
        return simpleDateFormat.format(new Date()); // 获取当前时间字符串
    }

    public Date getDateAdd(int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + days);//让日期加
        return calendar.getTime();
    }

    public String getFormatDate(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
        return simpleDateFormat.format(date);
    }
}
